<?php
$loader->requireOnce('includes/LabResult/LabAssignedItemModel.class.php');
/**
 * lab model 
 * @package modules.dept_laboratory.includes
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class LabResultModel {
	private $listOfLabAssignedItemModel = array();
    var $labTicketOrdo     = '';   
    private $done = false;
    
	function __construct($labTicketId) {
		$this->labTicketOrdo = Celini::newOrdo('LabTicket');
		$this->labTicketOrdo->setup($labTicketId);
		$this->buildLabAssignedItemModel($labTicketId);
	}
	public function getLabAssignedItemsModel() {
		return $this->listOfLabAssignedItemModel;
	}
	
	public function saveData($metaData, $resultData) {
		//save meta data
		$metaData['modified'] = date("Y-m-d H:i:s");
		$this->labTicketOrdo->setData($metaData);
		$this->labTicketOrdo->persist();
		//save result
		$this->done = false;
		
		foreach ($this->listOfLabAssignedItemModel as &$item) {
            //add into array
            $item->saveData($resultData);
            if ($item->isDone() == true) {
            	$this->done = true;
            	
            }          
        }  

        $this->labTicketOrdo->setDone($this->done);
		
	}	
	
	public function getLabTicketOrdo() {
		return $this->labTicketOrdo;
	}	
	
	private function buildLabAssignedItemModel($labTicketId) {
		$labAssignedObj = Celini::newOrdo('LabAssignedItem');
		$listOfItems = $labAssignedObj->listLabAssignedItems($labTicketId, true);
		foreach ($listOfItems as $item) {
			//add into array
			$this->listOfLabAssignedItemModel[] = new LabAssignedItemModel($item['lab_assigned_item_id']);			
		}		
	}
	
    
}
?>